home *** CD-ROM | disk | FTP | other *** search
/ E.M.Computergraphic Phase 4 / Phase 4 - Desktop Video Dreams (E. M. Computergraphic)(1996).iso / utilities / imagestudio / rexx / batchprocessnotify.isrx < prev    next >
Text File  |  1996-01-17  |  8KB  |  335 lines

  1. /* ImageStudio ARexx script **************************************/
  2.  
  3. /* Allow commands to return results */
  4.  
  5. options results
  6.  
  7. /* On error, goto ERROR:. Comment out this line if you wish to */
  8. /* perform your own error checking. */
  9.  
  10. signal on error
  11.  
  12. /* BEGIN PROGRAM *************************************************/
  13.  
  14. /* Warn the user if they are about to overwrite their current project */
  15.  
  16. IMAGEINFO_GET STEM imageinfo.
  17.  
  18. if imageinfo.changed == 1 then
  19.     REQUEST_MESSAGE TEXT '"Project has changed, continue?"',
  20.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  21.  
  22. /* Choose source file */
  23.  
  24. REQUEST_MESSAGE TEXT '"Choose final filename in sequence\n'||,
  25.     'on which to start the processing..."',
  26.     BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  27.  
  28. REQUEST_FILE VAR finalfile
  29.  
  30. /* Get the basefilename */
  31.  
  32. FILE_RENAME FILE '"'finalfile'"' FROM "." TO "." VAR basefile
  33. FILE_SPLIT FILE '"'basefile'"' STEM splitinfo.
  34.  
  35. basefilepart = splitinfo.filepart
  36. basepathpart = splitinfo.pathpart
  37.  
  38. /* Use separate destination directory ? */
  39.  
  40. REQUEST_MESSAGE TEXT '"Use different destination directory?"',
  41.     BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  42.  
  43. if result == 1 then
  44.     REQUEST_DIR TITLE '"Choose destination directory..."' VAR destdir
  45. else
  46.     destdir = ':NONE:'
  47.  
  48. REQUEST_LIST TITLE '"Choose output format..."' STRINGS,
  49.     '"IFF-ILBM"',
  50.     '"BMP"',
  51.     '"EPS"',
  52.     '"GIF"',
  53.     '"JPEG"',
  54.     '"PCX"',
  55.     '"Targa"' STEM saveformat.
  56.  
  57. /* Set up a blank ARGS string, which we can add to */
  58.  
  59. saveargs = 'ARGS "'
  60.  
  61. /* Get any IFF-ILBM args ? */
  62.  
  63. if saveformat.string == 'IFF-ILBM' then do
  64.     /* Get a subformat */
  65.  
  66.     REQUEST_MESSAGE TEXT '"Choose ILBM format..."' BUTTONTEXT,
  67.         '"As buffer|HAM6|HAM8|EHB|Cancel"' AUTOCANCEL
  68.  
  69.     /* Store subformat */
  70.  
  71.     if result == 2 then
  72.         saveargs = saveargs||'SUBFORMAT HAM6'
  73.     else if result == 3 then
  74.         saveargs = saveargs||'SUBFORMAT HAM8'
  75.     else if result == 4 then
  76.         saveargs = saveargs||'SUBFORMAT EHB'
  77.  
  78.     /* Get the dither if not saving as buffer */
  79.  
  80.     if result ~= 1 then do
  81.         REQUEST_MESSAGE TEXT '"Choose ILBM dither..."' BUTTONTEXT,
  82.             '"None|Floyd-Steinberg|Cancel"' AUTOCANCEL
  83.  
  84.         /* Store the dither */
  85.  
  86.         if result == 2 then
  87.             saveargs = saveargs||' DITHER FS'
  88.  
  89.         end
  90.  
  91.     /* Ask whether should set screenmode of images */
  92.  
  93.     REQUEST_MESSAGE TEXT '"Set screenmode of images?"',
  94.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  95.  
  96.     if result == 1 then do
  97.         setscreenmode = 1
  98.  
  99.         REQUEST_SCREENMODE STEM screenmode.
  100.  
  101.         imagescreenmode = screenmode.modeid
  102.  
  103.         end
  104.     else
  105.         setscreenmode = 0
  106.     end
  107. else if saveformat.string == 'EPS' then do
  108.     /* Get the DPI of the image */
  109.  
  110.     REQUEST_STRING TEXT1 '"Enter the DPI resolution of"',
  111.         TEXT2 '"the EPS files to be saved:"',
  112.         STRING 300 VAR dpiinfo
  113.  
  114.     saveargs = saveargs||dpiinfo
  115.  
  116.     /* Ask whether to save as colour or greyscale */
  117.  
  118.     REQUEST_MESSAGE TEXT '"Greyscale or colour EPS?"' BUTTONTEXT,
  119.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  120.  
  121.     if result == 2 then
  122.         saveargs = saveargs||' COLOUR'
  123.  
  124.     end
  125. else if saveformat.string == 'JPEG' then do
  126.     /* Get the DPI of the image */
  127.  
  128.     REQUEST_STRING TEXT1 '"Enter the JPEG quality setting"',
  129.         TEXT2 '"for the files to be saved."',
  130.         TEXT3 '"(Valid values 25 to 100):"',
  131.         STRING 75 VAR qualityinfo
  132.  
  133.     saveargs = saveargs||qualityinfo
  134.  
  135.     /* Ask whether to save as colour or greyscale */
  136.  
  137.     REQUEST_MESSAGE TEXT '"Greyscale or colour JPEG?"' BUTTONTEXT,
  138.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  139.  
  140.     if result == 1 then
  141.         saveargs = saveargs||' GREYSCALE'
  142.  
  143.     end
  144.  
  145. /* We may or may not have created an ARGS string. If we have, lets */
  146. /* finish it off, else lets delete it */
  147.  
  148. if saveargs == 'ARGS "' then
  149.     saveargs = ''
  150. else
  151.     saveargs = saveargs||'"'
  152.  
  153. /* Rename filenames ? */
  154.  
  155. REQUEST_MESSAGE TEXT '"Rename filenames ?"' BUTTONTEXT,
  156.     '"Yes|No|Cancel"' AUTOCANCEL
  157.  
  158. if result == 1 then do
  159.     /* Set the rename files */
  160.  
  161.     renamefiles = 1
  162.  
  163.     /* Get the rename pattern */
  164.  
  165.     REQUEST_STRING TEXT1 '"Choose the filename extension. For"',
  166.         TEXT2 '"example: . .ILBM would rename all"',
  167.         TEXT3 '"files to .ILBM, see docs for more info"',
  168.         STRING '". .'||saveformat.string||'"',
  169.         VAR renamestring
  170.     end
  171. else
  172.     renamefiles = 0
  173.  
  174. /* If we're renaming, we should ask if they want the source file */
  175. /* deleted. If we're not renaming, we should warn the user that */
  176. /* the source file will be overwritten. */
  177.  
  178. if renamefiles == 1 then do
  179.     REQUEST_MESSAGE TEXT '"Delete source files ?"',
  180.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  181.  
  182.     if result == 1 then
  183.         deletesource = 1
  184.     else
  185.         deletesource = 0
  186.     end
  187. else if renamefiles == 0 & destdir == ':NONE:' then
  188.     REQUEST_MESSAGE TEXT '"WARNING : Source files will\nbe overwritten."',
  189.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  190.  
  191. /* Ask user for process(s) to apply to image before saving out */
  192.  
  193. REQUEST_STRING TITLE '"Enter processes to apply..."',
  194.     TEXT1 '"Enter the processes to apply before"',
  195.     TEXT2 '"saving out the image (separate "',
  196.     TEXT3 '"commands with semi-colon ;)"' VAR process
  197.  
  198. /* Wait for finalfile to change */
  199.  
  200. NOTIFY_FILE FILE '"'finalfile'"'
  201.  
  202. /* Get all files that match the basefile */
  203.  
  204. FILES_MATCH PATHPART '"'basepathpart'"' PATTERN '"'basefilepart||'#?"',
  205.     STEM srcfiles.
  206.  
  207. /* Loop around and convert all the files */
  208.  
  209. do l = 0 to (srcfiles.fileparts.count - 1)
  210.     /* Construct the source file */
  211.  
  212.     FILE_JOIN PATHPART '"'basepathpart'"' FILEPART,
  213.         '"'srcfiles.fileparts.l'"' VAR 'srcfile'
  214.  
  215.     /* Open the file */
  216.  
  217.     OPEN FILE '"'srcfile'"' FORCE
  218.  
  219.     /* If you wish to customize this macro to perform any operations */
  220.     /* on the image before saving it out (e.g. resizing, colour */
  221.     /* reduction etc...), add the commands here */
  222.  
  223.     interpret process
  224.  
  225.     /* Set the screenmode if neccessary */
  226.  
  227.     if setscreenmode == 1 then
  228.         IMAGEINFO_SET MODEID imagescreenmode
  229.  
  230.     /* Create the output filename */
  231.  
  232.     if destdir ~= ':NONE:' then do
  233.         /* Get the filepart of the src filepart */
  234.  
  235.         FILE_SPLIT FILE '"'srcfiles.fileparts.l'"',
  236.             STEM 'splitinfo.'
  237.  
  238.         /* Create the destfile */
  239.  
  240.         FILE_JOIN PATHPART '"'destdir'"',
  241.             FILEPART '"'splitinfo.filepart'"' VAR 'destfile'
  242.  
  243.         end
  244.     else
  245.         destfile = srcfile
  246.  
  247.     /* Rename file ? */
  248.  
  249.     if renamefiles == 1 then 
  250.         FILE_RENAME FILE '"'destfile'"' renamestring,
  251.             VAR 'destfile'
  252.  
  253.     /* Save the fileout in the new format */
  254.  
  255.     SAVE FILE '"'destfile'"' FORMAT '"'saveformat.string'"',
  256.         saveargs FORCE
  257.  
  258.     /* Delete source file (and icon) if required */
  259.  
  260.     if renamefiles == 1 & deletesource == 1 then do
  261.         /* Make sure hasn't been renamed to same name */
  262.  
  263.         if upper(srcfile) == upper(destfile) then
  264.             break
  265.  
  266.         address command 'delete <NIL: >NIL: "'srcfile.'"'
  267.  
  268.         if exists(srcfile'.info') == 1 then
  269.             address command 'delete <NIL: >NIL: "'||,
  270.                 srcfile'.info"'
  271.         end
  272.     end
  273.  
  274.  
  275. /* END PROGRAM ***************************************************/
  276.  
  277. exit
  278.  
  279. /* On ERROR */
  280.  
  281. ERROR:
  282.  
  283. /* If we get here, either an error occurred with the command's */
  284. /* execution or there was an error with the command itself. */
  285. /* In the former case, rc2 contains the error message and in */
  286. /* the latter, rc2 contains an error number. SIGL contains */
  287. /* the line number of the command which caused the jump */
  288. /* to ERROR: */
  289.  
  290. if datatype(rc2,'NUMERIC') == 1 then do
  291.     /* See if we can describe the error with a string */
  292.  
  293.     select
  294.         when rc2 == 103 then
  295.             err_string = "ERROR 103, "||,
  296.                 "out of memory at line "||SIGL
  297.         when rc2 == 114 then
  298.             err_string = "ERROR 114, "||,
  299.                 "bad command template at line "||SIGL
  300.         when rc2 == 115 then
  301.             err_string = "ERROR 115, "||,
  302.                 "bad number for /N argument at line "||SIGL
  303.         when rc2 == 116 then
  304.             err_string = "ERROR 116, "||,
  305.                 "required argument missing at line "||SIGL
  306.         when rc2 == 117 then
  307.             err_string = "ERROR 117, "||,
  308.                 "value after keywork missing at line "||SIGL
  309.         when rc2 == 118 then
  310.             err_string = "ERROR 118, "||,
  311.                 "wrong number of arguments at line "||SIGL
  312.         when rc2 == 119 then
  313.             err_string = "ERROR 119, "||,
  314.                 "unmatched quotes at line "||SIGL
  315.         when rc2 == 120 then
  316.             err_string = "ERROR 120, "||,
  317.                 "line too long at line "||SIGL
  318.         when rc2 == 236 then
  319.             err_string = "ERROR 236, "||,
  320.                 "unknown command at line "||SIGL
  321.         otherwise
  322.             err_string = "ERROR "||rc2||", at line "||SIGL
  323.         end
  324.         end
  325. else if rc2 == 'RC2' then do
  326.     err_string = "ERROR in command at line "||SIGL
  327.     end
  328. else do
  329.         err_string = rc2||", line "||SIGL
  330.         end
  331.  
  332. request_message TEXT '"'err_string'"'
  333.  
  334. exit
  335.